package com.itbaiwei.unitday01.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

/**
 * Class: MyLinearLayout
 * Description:
 * Author: haijun.xu
 * Date: 2025/5/28 11:35
 */
public class MyLinearLayout extends LinearLayout {

    private float lastX,lastY;

    public MyLinearLayout(Context context) {
        super(context);
    }
    public MyLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }
    public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        float x = ev.getX();
        float y = ev.getY();
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                System.out.println("MotionEvent.ACTION_DOWN-------X:"+ev.getX());
                lastX=x;
                break;
            case MotionEvent.ACTION_MOVE:

                float delatX=x-lastX;
                System.out.println("移动间距："+delatX);
                break;
        }
        //及时更新上一次坐标
        lastX=x;

        return true;
    }




}
